<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>项目建设阶段、目标及资金使用计划</title>
<%@ include file="/common/meta.jsp"%>
<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>

<style type="text/css">
	.input_width { width:130px }
	.select_width { width:143px }
	.table_td td {border:0}
	.long_input{ width:642px }
    .selectWidth4{width:616px;}
    .table_tmp {  border-collapse:collapse;/*细线表格代码*/ }
	.table_tmp td { border:1px solid #b7d1e6;/*细线表格线条颜色*/ padding:4px; }
	.table_tmp th { border:1px solid #b7d1e6; font-weight:bold; text-align:center; background:#edf2f8; padding:4px; }
</style>
<script type="text/javascript">
var type = "${param.type}";
var parentTable = parent.$("#"+"${param.parentTab}");	//父页面的表格
var selectRadio = $();									//父页面选中的单选框
var selectTr = $();										//父页面选中的行

if(type=="edit") {
	selectRadio = parentTable.find(":radio:checked");
	selectTr = selectRadio.parents("tr");
}

$(function(){
	$("#tab1").click();
	$("#fragment-tab1 :text,#fragment-tab1 [type='date']").addClass("input_width");
	$("#fragment-tab1 select").addClass("select_width");
	
	$("table.t_css").each(function(){
		$(this).find("tr:even").addClass("li_1");
		$(this).find("tr:odd").addClass("li_2");
	});
	
	
	if(type=="edit"){
		$("input:not(:radio:button),textarea").each(function(){
			var id=$(this).attr("name");
			if(id==null || id=="")
				return true;
			var parentObj=selectTr.find("[name$='/"+id+"']");
			var value="";
			if(parentObj.is("span"))
				value=parentObj.text();
			else
				value=parentObj.val();
			
			//if($(this).is("input"))//初始化input框 不包括radio
				$(this).val(value);
		});
		
		
		initTblEquipments();
		
	}
	
	function initTblEquipments(){
		var xmlStr = $("#equipments").val();
		
		var reg = /[\r\n]/g;
		xmlStr=xmlStr.replace(reg,""); 
		if(xmlStr==null || xmlStr=="")
			return false;
		
		var equipmentNode = /<equipment[^s](.\n?)+?<\/equipment>/g;
		var equipment = xmlStr.match(equipmentNode);
		if(equipment != null){
			
			for(var i=0; i<equipment.length; i++){
				$("#cmdAddbefore").click();
				equipment[i] = equipment[i].replace(reg,"");
				var j = i + 1;
				
				var cname = equipment[i].match(/<cname(.\n?)+?<\/cname>/);
				if(cname != null){
					cname = cname[0].replace(/<cname.*?>|<\/cname>/g,"");
					$("#equipment" + j +"_cname").val(cname);
				}
				var model = equipment[i].match(/<model(.\n?)+?<\/model>/);
				if(model != null){
					model = model[0].replace(/<model.*?>|<\/model>/g,"");
					$("#equipment" + j +"_model").val(model);
				}
				
				var standard = equipment[i].match(/<standard(.\n?)+?<\/standard>/);
				if(standard != null){
					standard = standard[0].replace(/<standard.*?>|<\/standard>/g,"");
					$("#equipment" + j +"_standard").val(standard);
				}
				var amount = equipment[i].match(/<amount(.\n?)+?<\/amount>/);
				if(amount != null){
					amount = amount[0].replace(/<amount.*?>|<\/amount>/g,"");
					$("#equipment" + j +"_amount").val(amount);
				}
				var price = equipment[i].match(/<price(.\n?)+?<\/price>/);
				if(price != null){
					price = price[0].replace(/<price.*?>|<\/price>/g,"");
					$("#costs_0_" + j).val(price);
				}
				
			}
		}
	}
	
	function savePsn(){
		$("textarea").each(function(){
			var val=$(this).val();
			//alert(val.indexOf(" ")+"=="+val.lastIndexOf(" "));
			val = val.replace(/&/gi,"&amp;").replace(/</gi,"&lt;").replace(/>/gi,"&gt;").replace(/\n/gi,"<br>").replace(/\s/gi,"&nbsp;").replace(/"/gi,"&quot;");
			//alert("input[nam*="+$(this).attr('name')+"_hidden]");
		
			$("input[name='"+$(this).attr('name')+"_hidden']").val(val);
				
			//$(this).html(val);
		});
		//填写检查接口
		saveResearch("researchTbl");
		validate($("#fragment-tab1"),"项目建设阶段、目标");
		//validate($("#fragment-tab2"),"资金使用计划");
		irisJqValEmpty($("#ry_cost"),"资金使用计划-->人员费不能为空");
		irisJqValEmpty($("#wx_cost"),"资金使用计划-->外协费用不能为空");
		irisJqValEmpty($("#sb_cost"),"资金使用计划-->仪器设备费不能为空");
		irisJqValEmpty($("#qt_cost"),"资金使用计划-->其他费用不能为空");
		validateByTabRow($("#tblEquipments"),"资金使用计划->仪器设备详情",1);
		if(!valResult()){
			irisValShowMsg($("#savePsn"));
			return false;
		}
		//添加新行
		if(type=="add") {
			addNewRowDeal(parentTable);
		}
		
		var xmldate = prePareXmlDataStand($("#tblEquipments"), "", "");
		$("#equipments").val(xmldate.replace(/<equipments.*?>|<\/equipments>/g,""));
		
		$("input:not(:radio:button),textarea").each(function(){
			
			var id=$(this).attr("name");
			var parentObj=null;
			
			if(id==null || id=="")
				return true;
			
			//获得父页面的对象
			if(type=="add"){
				parentObj=parentTable.find("tr:last-child").find("[name$='/"+id+"']");
			}else if(type=="edit"){
				parentObj=selectTr.find("[name$='/"+id+"']");
			}

			if(parentObj!=null){
				if(parentObj.is("span")){
					parentObj.text($(this).val());	//将值写回父页面
				}
				else{
					parentObj.val($(this).val());
				}
			}
			
		});
		
		if(type=="add"){
			parentTable.find("tr:last :radio").attr("checked",true);
			if("${param.parentTab}"=="zh_persons")
				parent.setSubmitPsn();
		}
		
		//if(confirm("保存成功，是否返回申请书页面"))
		//	parent.tb_remove();
		//else
		$(".wBox_popup").hide();
		if(confirm("保存成功，是否返回申请书页面"))
			parent.tb_remove();
		else if(type=="add"){
			type = "edit";
			selectRadio = parentTable.find(":radio:checked");	//父页面选中的单选框
			selectTr = selectRadio.parents("tr");				//父页面选中的行
		}
	}
	
	$("#savePsn").click(function(){
		setTimeout(savePsn,100);
	});
});

function loadAjaxSelect(selectId,url,params,varParm){
	$.ajax( {
		url : url,
		type : 'post',
		dataType:'json',
		data : params,
		success : function(data) {
			
			for(var i=0;i<data.length;i++){
				var value=data[i].id;
				var text=data[i].name;		
				$("#"+selectId).append("<option value='"+value+"'>"+text+"</option>");
				

			}
			if(type=="edit"){//如果是修改，才需要初始化select框的值
				var selectValue=$("[name='"+selectId+"_value']").val();
				$("#"+selectId+" option").each(function(i,obj){
					if($(obj).val()==selectValue){
						setTimeout(function() {
							$(obj).attr("selected",true);
						}, 1);
					}
				});
			}
			
				
		}
	});
	}


</script>

</head>
<body>

	<div id="tabnav">
		<ul>
			<li class="down" id="tab1" onclick="changeTab(this.id)">
					<a href="###"><span>项目建设阶段、目标</span></a>
			</li>
			<li class="down" id="tab2" onclick="changeTab(this.id)">
					<a href="###"><span>资金使用计划</span></a>
			</li>
		</ul>
	</div>
	
	<div class="tab_box" id="fragment-tab1">
		<table class="t_css" width="665px" border="0" cellpadding="0" label="项目计划" cellspacing="1">
		<tr>
			<td nowrap align="right" width="100px"><span class="color_red">*</span>开始日期：</td>
			<td width="180px">
				<cpt:date id="start_date"  value="" className="required date dateCompare:end_date" label="开始日期"   name="start_date"></cpt:date> 
			</td>
			<td align="right" nowrap width="100px">
				<span class="color_red">*</span>结束日期：
			</td>
			<td>
				<cpt:date id="end_date"  value="" className="required date" label="结束日期"   name="end_date"></cpt:date>
			</td>
		</tr>

		<tr>
			<td align="right">
				<span class="color_red">*</span>建设目标及建设进度指标：<br/>(限500字)
			</td>
			<td colspan="3">
				<textarea name="content" rows="5" style="width:500px" class="input_textarea required  textarea maxlength:500" required label="建设目标及建设进度指标" ></textarea>
			    <input type="hidden" name="content_hidden" value="">
			</td>
		</tr>
		</table>
			
			
			
	</div>
	<div class="tab_box" id="fragment-tab2"  style="display:none">
	<table class="t_css" width="665px" border="0" cellpadding="0" label="资金使用计划" cellspacing="1">
		<tr>
			<td align="right" width="150px">
				资金统计：
			</td>
			<td colspan="3">
				<input type="text" name="total_costs" id="costs_0" disabled label="资金统计" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:130px;" class="required input_text maxlength:50 gray" maxlength="50"/>（万元）
			</td>
			
		</tr>
		<tr>
			<td align="right">
				<span class="color_red">*</span>1、人员费：
			</td>
			<td id="ry_cost" nowrap>
				<input type="text" name="personnel_costs" id="costs_1"  label="人员费" onchange="countFund('costs_','1,2,3,4','0');" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:130px;" class="required input_text maxlength:50" maxlength="50"/>（万元）
			</td>
			
			<td align="right" width="150px">
				<span class="color_red">*</span>2、外协费用：
			</td>
			<td id="wx_cost" nowrap>
				<input type="text" name="outsourcing_costs"  id="costs_2" label="外协费用" onchange="countFund('costs_','1,2,3,4','0');" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:130px;" class="required input_text maxlength:50" maxlength="50"/>（万元）
			</td>
			
		</tr>
		<tr>
			<td align="right"><span class="color_red">*</span>3、仪器设备费：</td>
			<td id="sb_cost" nowrap>
				<input type="text" label="仪器设备费" id="costs_3" disabled onchange="countFund('costs_','1,2,3,4','0');" name="equipments/equipment_total_costs" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:130px;" class="required gray" maxlength="50"/>（万元）
			</td>
			<td align="right"><span class="color_red">*</span>4、其他费用：</td>
			<td id="qt_cost" nowrap>
				<input type="text" label="其他费用" name="other_costs"  id="costs_4"  onchange="countFund('costs_','1,2,3,4','0');" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:130px;" class="required" maxlength="50"/>（万元）
			</td>
		</tr>
	</table>
	<input type="hidden" id="equipments" name="equipments" >
	<table  id="tblEquipments" cellpadding="0" class="table_tmp" width="665px" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<thead>
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center"  width="30px">选择</th>
						<th class="TblHead" align="center"  width="30px">序号</th>
						<th class="TblHead" align="center"  width="80px">设备名称</th>
						<th class="TblHead" align="center"  width="80px">型号</th>
						<th class="TblHead" align="center"  width="80px">规格</th> 
						<th class="TblHead" align="center"  width="70px">数量</th> 
						<th class="TblHead" align="center"  width="70px">价格（万元）</th> 
					</tr>
			</thead>
			<tbody id="tab">
					<tr  style="display:none">
						<td align="center">&nbsp;
							<input type="radio" class="radiobutton" name="selEquipments" >
						</td>
						<td align="center">&nbsp;
							<span name="equipments|equipment[0]@seq_no" >[index]</span> 
						</td>
						<td>
							<input type="text" name="equipments|equipment[0]|cname" id="equipment[index]_cname" label="名称" style="width:100px;" class="input_text required maxlength:50" maxlength="50"/>
						</td>
						<td>
							<input type="text" name="equipments|equipment[0]|model" id="equipment[index]_model" label="型号" style="width:100px;" class="input_text required maxlength:50" maxlength="50"/>
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|standard" id="equipment[index]_standard" label="规格" style="width:100px;" class="input_text required maxlength:50" maxlength="50"/>
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|amount" id="equipment[index]_amount" label="数量" style="text-align:right;width:50px;" class="input_text required maxlength:50" maxlength="50" onfocus="InitInput.setNumber(this,7,0,0)" />
						</td> 
						<td>
							<input type="text" name="equipments|equipment[0]|price" id="costs_0_[index]" label="价格" onchange="countFund('costs_','0_1,0_2,0_3,0_4,0_5','3');countFund('costs_','1,2,3,4','0');" onfocus="InitInput.setNumber(this,7,4,2)" style="text-align:right;width:50px;" class="input_text required maxlength:50" maxlength="50"/>
						</td> 
					</tr>
					
				</tbody>
			</table>
			<br>
			<table>
			  <tr >
				<td colspan="6">
					<input class="button" name="cmdAddbefore" type=button value="添加" id="cmdAddbefore"
						onclick="if(checkTabLimit('tblEquipments',5,'现有主要仪器设备最多只能填写5条')){addNewRow('tblEquipments');showDateTag('tblEquipments');}try{top.resizeFrame();}catch(e){};">
					<input class="button" name="cmdMovePrev" type=button value="上移" onclick="movePrev('tblEquipments','selEquipments')">
					<input class="button" name="cmdMoveNext" type=button value="下移" onclick="moveNext('tblEquipments','selEquipments')">
					<input class="button" name="cmddel" type=button  value="删除" onclick="deleteSelectedRow('tblEquipments','设备详情');countFund('costs_','0_1,0_2,0_3,0_4,0_5','3');countFund('costs_','1,2,3,4','0');">
				</td>
				</tr>
			</table>
	</div>
	<br>
			<table width="100%" align="center">
				<tr>
					<td><input type="button"  class="button_01 notdisabled" id="savePsn" value="保存">
						&nbsp;<input type="button" id="cancel" class="button_01 notdisabled" value="取消" onclick="parent.tb_remove();">
					</td>
				</tr>
			</table>
</body>
</html>